<template>
    <div class="content">
        <div class="text">管理员登录</div>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
            <el-form-item class="field" prop="username">
                <el-input
                    v-model="ruleForm.username"
                    type="text"
                    placeholder="用户名"
                    required
                />
                <span class="fas fa-user"></span>
                <!-- Font Awesome Icon -->
            </el-form-item>
            <el-form-item class="field" prop="password">
                <el-input
                    v-model="ruleForm.password"
                    type="password"
                    placeholder="密码"
                    required
                />
                <span class="fas fa-lock"></span>
            </el-form-item>
            <el-form-item>
                <el-button @click="submitForm('ruleForm')">登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    data() {
        return {
            ruleForm: {
                username: "",
                password: "",
            },
            rules: {
                username: [
                    {
                        required: true,
                        message: "请输入用户名",
                        trigger: "blur",
                    },
                    {
                        min: 4,
                        max: 15,
                        message: "长度在 4 到 15 个字符",
                        trigger: "blur",
                    },
                ],
                password: [
                    {
                        required: true,
                        message: "请输入密码",
                        trigger: "blur",
                    },
                    {
                        min: 4,
                        max: 15,
                        message: "长度在 4 到 15 个字符",
                        trigger: "blur",
                    },
                ],
            },
        };
    },
    methods: {
        submitForm: function(formName) {
            // this.$refs[formName].validate((valid) => {
            //     if (valid) {
            //         let url = "http://localhost:9081/admins/login";
            //         console.log("url = " + url);
            //         let formData = this.qs.stringify(this.ruleForm);
            //         this.axios.post(url, formData).then((response) => {
            //             let responseBody = response.data;
            //             if (responseBody.state == 20000) {
            //                 this.$message({
            //                     message: "登录成功！",
            //                     type: "success",
            //                 });
            //                 // 获取服务器端响应的JWT，并存储到LocalStorage
            //                 let jwt = responseBody.data;
            //                 console.log("登录成功，服务器响应的JWT=" + jwt);
            //                 localStorage.setItem("jwt", jwt);
            //                 this.$router.push("/sys-admin/index");
            //                 // 以下是测试
            //                 // let localJwt = localStorage.getItem('jwt');
            //                 // console.log('从LocalStorage中读取JWT：' + localJwt);
            //             } else {
            //                 this.$message.error(responseBody.message);
            //             }
            //         });
            //     } else {
            //         console.log("error submit!!");
            //         return false;
            //     }
            // });
            console.log("click on login button");
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
    },
};
</script>

<style>
@import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css");
@import url("https://fonts.googleapis.com/css?family=Poppins:400, 500, 600, 700, 800, 900&display=swap");

* {
    margin: 0;
    padding: 0;
    /* user-select: none; */
    box-sizing: border-box;
    font-family: sans-serif;
}

html,
body {
    height: 100%;
}

body {
    display: grid;
    place-items: center;
    background: #dde1e7;
    text-align: center;
}
.content {
    width: 330px;
    padding: 40px 30px;
    background: #dde1e7;
    border-radius: 10px;
    box-shadow: -3px -3px 7px #ffffff73, 2px 2px 5px rgba(94, 104, 121, 0.288);
}

.content .text {
    font-size: 33px;
    font-weight: 600;
    margin-bottom: 35px;
    color: #595959;
}

.field .el-form-item__content {
    height: 50px;
    width: 100%;
    display: flex;
    position: relative;
}

.field:nth-child(2) {
    margin-top: 20px;
}

.field input {
    height: 50px;
    width: 100%;
    padding-left: 45px;
    outline: none;
    border: none;
    font-size: 18px;
    background: #dde1e7;
    color: #595959;
    border-radius: 25px;
    box-shadow: inset 2px 2px 5px #babecc, inset -5px -5px 10px #ffffff73;
}

.field input:focus {
    box-shadow: inset 1px 1px 2px #babecc, inset -1px -1px 2px #ffffff73;
}

.field label {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 45px;
    pointer-events: none;
    color: #666666;
}

input::placeholder {
    font-weight: bold;
    opacity: 1;
    color: red;
}

.field span {
    position: absolute;
    color: #595959;
    width: 50px;
    right: 220px;
    line-height: 50px;
}

.el-form-item__content button {
    margin: 15px 0;
    padding: 0;
    width: 100%;
    height: 50px;
    font-size: 18px;
    line-height: 50px;
    font-weight: 600;
    background: #dde1e7;
    border-radius: 25px;
    border: none;
    outline: none;
    cursor: pointer;
    color: #595959;
    box-shadow: 2px 2px 5px #babecc, -5px -5px 10px #ffffff73;
}

.el-form-item__content button:focus {
    color: #3498db;
    box-shadow: inset 2px 2px 5px #babecc, inset -5px -5px 10px #ffffff73;
}

.el-form-item__label::before {
    content: "" !important;
}
</style>
